package com.youfang.sixthmedia;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.gzit.utils.AndroidUtils;

/**
 * 主屏
 * 
 * @author teddy
 * 
 */
public class BakMainActivity extends Activity {

	static class PotalItem {
		int icon;
		String desc;

		public PotalItem(int icon, String desc) {
			super();
			this.icon = icon;
			this.desc = desc;
		}

	}

	class PotalAdapter extends BaseAdapter {

		PotalItem[] potals = new PotalItem[] {
				new PotalItem(R.drawable.ic_new, "新楼盘"),
				new PotalItem(R.drawable.ic_seacher, "楼盘搜索"),
				new PotalItem(R.drawable.ic_nearby, "附近楼盘"),
				new PotalItem(R.drawable.ic_tuangou, "团购楼盘"),
				new PotalItem(R.drawable.ic_discount, "优惠楼盘"),
				new PotalItem(R.drawable.ic_friend, "附近房友"),
				new PotalItem(R.drawable.ic_person, "个人中心"),
				new PotalItem(R.drawable.ic_calc, "房贷计算器"),
				new PotalItem(R.drawable.ic_setting, "更多")

		};

		@Override
		public int getCount() {
			return potals.length;
		}

		@Override
		public Object getItem(int index) {
			return potals[index];
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			PotalItem item = (PotalItem) this.getItem(position);
			View view = convertView == null ? getLayoutInflater().inflate(
					R.layout.portal_item, null) : convertView;

			ImageView icon = (ImageView) view.findViewById(R.id.icon);
			TextView desc = (TextView) view.findViewById(R.id.desc);

			desc.setText(item.desc);
			icon.setImageResource(item.icon);

			return view;

		}
	}

	private GridView gridview;
	private PotalAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		AndroidUtils.Screen.noWindowTitle(this);
		this.setContentView(R.layout.main_activity);

		/*
		 * gridview = (GridView) this.findViewById(R.id.gridview); adapter = new
		 * PotalAdapter(); gridview.setAdapter(adapter);
		 * 
		 * gridview.setOnItemClickListener(new OnItemClickListener() {
		 * 
		 * @Override public void onItemClick(AdapterView<?> arg0, View arg1, int
		 * arg2, long arg3) {
		 * 
		 * // 跳到指定的界面
		 * 
		 * }
		 * 
		 * });
		 * 
		 * gridview.invalidate();
		 */

		this.findViewById(R.id.newb).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				gotoTabActivity();
			}
		});

	}

	private void gotoTabActivity() {
		
		Intent intent = new Intent();
		intent.setClass(this, TabMainActivity.class);
		this.startActivity(intent);

	}

}
